<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <title>编辑</title>
    <script type="text/javascript" th:src="@{/jquery.min.js}"></script>
    <script>
        $(document).ready(function () {
            let id = $("#id").val()
            if (id) {
                getResumeById($("#id").val())
            }

            function getResumeById(id) {
                $.ajax({
                    url: '/resume/' + id,
                    type: 'GET',
                    contentType: 'application/json;charset=utf-8',
                    dataType: 'json',
                    success: function (data) {
                        if (data != null) {
                            $("#name").val(data.name)
                            $("#phone").val(data.phone)
                            $("#address").val(data.address)
                        }
                    }
                })
            }

            $("#save").click(function () {
                let id = $("#id").val()
                let data = {
                    'name': $("#name").val(),
                    'phone': $("#phone").val(),
                    'address': $("#address").val()
                };
                if (id){
                    data.id = id
                    data._method = 'PUT'
                }
                $.ajax({
                    url: '/resume',
                    type: 'POST',
                    data: JSON.stringify(data),
                    contentType: 'application/json;charset=utf-8',
                    dataType: 'json',
                    success: function (data) {
                        window.location.href = '/resume'
                    }
                })
            })
        })
    </script>
</head>
<body>
端口号:<span th:text="${#httpServletRequest.getLocalPort()}"></span>
当前用户:<span th:text="${session.user}"></span>
<form id="resumt">
    <input type="hidden" id="id" th:value="${id}">
    <label>
        名称:<input type="text" id="name">
    </label>
    <br>
    <label>
        电话:<input type="text" id="phone">
    </label>
    <br>
    <label>
        地址:<input type="text" id="address">
    </label>
    <br>
    <input type="button" id="save" value="保存">
</form>
</body>
</html>
